﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace 教师信息管理系统
{
    public partial class regedit : Form
    {
        SqlConnection conn;
        public regedit()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            main m = new main();
            m.Show();
            this.Hide();

        }

        private void button1_Click(object sender, EventArgs e)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = this.conn;
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "select usersid from userslogin where usersid='" + this.textBox1.Text + "'";
            string username = (string)cmd.ExecuteScalar();

            if ((this.textBox1.Text == "") || (this.textBox2.Text == ""))
            {
                MessageBox.Show("用户名或密码不能为空!");
                return;
            }
            else if (username != null)
            {
                MessageBox.Show("用户名已存在，请更换!");
                return;
            }
            else if (textBox3.Text == "" || (textBox2.Text != textBox3.Text))
            {
                MessageBox.Show("密码不能为空或密码不相等！");
                return;
            }
            else
            {
                cmd.CommandText = "insert into userslogin(usersid,psd) values('" + textBox1.Text + "','" + textBox2.Text + "')";
                int i = cmd.ExecuteNonQuery();
                MessageBox.Show("用户 " + textBox1.Text + " 注册成功!");

            }
        }

        private void regedit_Load(object sender, EventArgs e)
        {
            string sql = "server=.;database=teacher;integrated security=true;";
            conn = new SqlConnection(sql);
            conn.Open();
            if (conn.State == ConnectionState.Open)
            {
                this.Text = "用户注册（已连接!）";
            }
        }
    }
}
